/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
define(["ojs/ojcore","jquery","ojs/ojpagingtabledatasource"],function(a){a.Wf=function(a,b){this.Vw=a;this.yr=b};o_("PagingHeaderSet",a.Wf,a);a.Wf.prototype.getData=function(a,b){return this.Vw.getData(a+this.yr,b)};a.b.g("PagingHeaderSet.prototype.getData",{getData:a.Wf.prototype.getData});a.Wf.prototype.getMetadata=function(a,b){return this.Vw.getMetadata(a+this.yr,b)};a.b.g("PagingHeaderSet.prototype.getMetadata",{getMetadata:a.Wf.prototype.getMetadata});a.Wf.prototype.getCount=function(){return this.Vw.getCount()};
a.b.g("PagingHeaderSet.prototype.getCount",{getCount:a.Wf.prototype.getCount});a.Wf.prototype.getLevelCount=function(){return this.Vw.getLevelCount()};a.b.g("PagingHeaderSet.prototype.getLevelCount",{getLevelCount:a.Wf.prototype.getLevelCount});a.Wf.prototype.getExtent=function(a,b){return this.Vw.getExtent(a+this.yr,b)};a.b.g("PagingHeaderSet.prototype.getExtent",{getExtent:a.Wf.prototype.getExtent});a.Wf.prototype.getDepth=function(a,b){return this.Vw.getDepth(a+this.yr,b)};a.b.g("PagingHeaderSet.prototype.getDepth",
{getDepth:a.Wf.prototype.getDepth});a.Wf.prototype.vga=function(){return this.Vw};a.b.g("PagingHeaderSet.prototype.getHeaderSet",{vga:a.Wf.prototype.vga});a.Wf.prototype.zF=function(){return this.yr};a.b.g("PagingHeaderSet.prototype.getStartIndex",{zF:a.Wf.prototype.zF});a.mb=function(g){if(!(g instanceof a.Rr))throw new a.ia("Not a datagridatasource","Not a datagridatasource",a.ia.Vc.ERROR);this.Md=g;this.oa=0;this.Init()};o_("PagingDataGridDataSource",a.mb,a);a.b.sa(a.mb,a.Rr,"oj.PagingDataGridDataSource");
a.mb.prototype.Init=function(){a.mb.u.Init.call(this);this.AE()};a.b.g("PagingDataGridDataSource.prototype.Init",{Init:a.mb.prototype.Init});a.mb.prototype.AE=function(){this.Md.on("change",this.swa.bind(this))};a.mb.prototype.getPage=function(){return this.ge};a.b.g("PagingDataGridDataSource.prototype.getPage",{getPage:a.mb.prototype.getPage});a.mb.prototype.setPage=function(g,b){b=b||{};g=parseInt(g,10);try{a.mb.u.handleEvent.call(this,a.bd.O.BEFOREPAGE,{page:g,previousPage:this.ge})}catch(c){return Promise.reject(null)}this.wb=
null!=b.pageSize?b.pageSize:this.wb;b.startIndex=g*this.wb;var d=this.ge;this.ge=g;this.oa=b.startIndex;var e=this;return new Promise(function(a,c){e.Gg(b).then(function(){a(null)},function(){e.ge=d;e.oa=e.ge*e.wb;c(null)})})};a.b.g("PagingDataGridDataSource.prototype.setPage",{setPage:a.mb.prototype.setPage});a.mb.prototype.Gg=function(a){this.Gq=!0;this.oa=a.startIndex;var b=this;return new Promise(function(a){b.handleEvent("change",{operation:"sync",pageSize:b.wb});a(void 0)})};a.mb.prototype.fetch=
function(a){this.wb=a.pageSize+a.startIndex;a.startIndex=0;return this.Gg(a)};a.b.g("PagingDataGridDataSource.prototype.fetch",{fetch:a.mb.prototype.fetch});a.mb.prototype.getStartItemIndex=function(){return this.oa};a.b.g("PagingDataGridDataSource.prototype.getStartItemIndex",{getStartItemIndex:a.mb.prototype.getStartItemIndex});a.mb.prototype.getEndItemIndex=function(){return this.Qk};a.b.g("PagingDataGridDataSource.prototype.getEndItemIndex",{getEndItemIndex:a.mb.prototype.getEndItemIndex});a.mb.prototype.getPageCount=
function(){var a=this.totalSize();return-1==a?-1:Math.ceil(a/this.wb)};a.b.g("PagingDataGridDataSource.prototype.getPageCount",{getPageCount:a.mb.prototype.getPageCount});a.mb.prototype.swa=function(g){switch(g.operation){case "refresh":this.oa=0;this.handleEvent("change",{operation:"sync",pageSize:this.wb});this.handleEvent(a.Ba.O.REFRESH,null);break;case "reset":this.handleEvent(a.Ba.O.RESET,null);break;case "insert":this.handleEvent(a.Ba.O.ADD,{index:g.indexes.row});break;case "delete":this.handleEvent(a.Ba.O.REMOVE,
null);break;case "update":g.indexes.row=0<=g.indexes.row-this.oa?g.indexes.row-this.oa:-1;this.handleEvent("change",g);break;default:this.handleEvent("change",g),this.handleEvent(a.Ba.O.SYNC,null)}};a.mb.prototype.getCount=function(a){var b=this.Md.getCount(a);return"row"===a&&0<=b?this.oa+this.wb<b?this.wb:b-this.oa:b};a.b.g("PagingDataGridDataSource.prototype.getCount",{getCount:a.mb.prototype.getCount});a.mb.prototype.getCountPrecision=function(a){return this.Md.getCountPrecision(a)};a.b.g("PagingDataGridDataSource.prototype.getCountPrecision",
{getCountPrecision:a.mb.prototype.getCountPrecision});a.mb.prototype.fetchHeaders=function(a,b,c){null==this.Gq?null!=b&&b.success&&b.success.call(c.success,null,a,null):"row"===a.axis?(a.start+=this.oa,a.start+a.count>this.oa+this.wb&&(a.count=this.wb-a.start),this.cw={headerRange:a,callbacks:b,callbackObjects:c},this.Md.fetchHeaders(a,{success:this.CU.bind(this),error:this.Yxa.bind(this)},c)):this.Md.fetchHeaders(a,b,c)};a.b.g("PagingDataGridDataSource.prototype.fetchHeaders",{fetchHeaders:a.mb.prototype.fetchHeaders});
a.mb.prototype.CU=function(g,b,c){var d,e;this.cw.headerRange==b&&(b.start-=this.oa,b.count+=1,null!=g&&(d=new a.Wf(g,this.oa)),null!=c&&(e=new a.Wf(c,this.oa)),g=this.cw.callbacks.success,c=this.cw.callbackObjects.success,this.cw=null,g.call(c,d,b,e))};a.mb.prototype.Yxa=function(a){var b,c;b=this.cw.callbacks.error;c=this.cw.callbackObjects.error;this.cw=null;b.call(c,a)};a.mb.prototype.fetchCells=function(a,b,c){var d;if(null==this.Gq)d={getData:function(){return null},getMetaData:function(){return null},
getStart:function(){return 0},getCount:function(){return 0},getLevelCount:function(){return 0},getExtent:function(){return 0},getDepth:function(){return 1}},null!=b&&b.success&&b.success.call(c.success,d,a);else{for(d=0;d<a.length;d+=1)"row"===a[d].axis&&(a[d].start+=this.oa,a[d].start+a[d].count>this.oa+this.wb&&(a[d].count=this.wb-a[d].start));this.bw={cellRanges:a,callbacks:b,callbackObjects:c};this.Md.fetchCells(a,{success:this.rwa.bind(this),error:this.qwa.bind(this)},c)}};a.b.g("PagingDataGridDataSource.prototype.fetchCells",
{fetchCells:a.mb.prototype.fetchCells});a.mb.prototype.rwa=function(g,b){var c,d,e;if(!this.bw.cellRanges!=b){for(c=0;c<b.length;c+=1)"row"===b[c].axis&&(b[c].start-=this.oa,b[c].count+=1);c=new a.zl(g,this.oa);d=this.bw.callbacks.success;e=this.bw.callbackObjects.success;this.bw=null;this.Qk=this.oa+g.getCount("row")-1;this.handleEvent("sync",{data:Array(g.getCount("row")),startIndex:this.oa});d.call(e,c,b)}};a.mb.prototype.qwa=function(a){var b,c;b=this.bw.callbacks.error;c=this.bw.callbackObjects.error;
this.bw=null;b.call(c,a)};a.mb.prototype.keys=function(a){return this.Md.keys({column:a.column,row:a.row+this.oa})};a.b.g("PagingDataGridDataSource.prototype.keys",{keys:a.mb.prototype.keys});a.mb.prototype.indexes=function(a){a=this.Md.indexes(a);-1!=a.row&&(a.row-=this.oa);return a};a.b.g("PagingDataGridDataSource.prototype.indexes",{indexes:a.mb.prototype.indexes});a.mb.prototype.getCapability=function(a){return this.Md.getCapability(a)};a.b.g("PagingDataGridDataSource.prototype.getCapability",
{getCapability:a.mb.prototype.getCapability});a.mb.prototype.size=function(){var a;if(null==this.Gq)return-1;a=this.Md.getCount("row");return this.Md.getCount("row")>this.wb?this.wb:a};a.b.g("PagingDataGridDataSource.prototype.size",{size:a.mb.prototype.size});a.mb.prototype.sort=function(a,b,c){this.Md.sort(a,b,c)};a.b.g("PagingDataGridDataSource.prototype.sort",{sort:a.mb.prototype.sort});a.mb.prototype.totalSize=function(){return null==this.Gq?-1:this.Md.getCount("row")};a.b.g("PagingDataGridDataSource.prototype.totalSize",
{totalSize:a.mb.prototype.totalSize});a.mb.prototype.totalSizeConfidence=function(){return"actual"};a.b.g("PagingDataGridDataSource.prototype.totalSizeConfidence",{totalSizeConfidence:a.mb.prototype.totalSizeConfidence});a.mb.prototype.moveOK=function(a,b,c){return this.Md.moveOK(a,b,c)};a.b.g("PagingDataGridDataSource.prototype.moveOK",{moveOK:a.mb.prototype.moveOK});a.mb.prototype.move=function(a,b,c,d,e){this.Md.move(a,b,c,d,e)};a.b.g("PagingDataGridDataSource.prototype.move",{move:a.mb.prototype.move});
a.zl=function(a,b){this.sN=a;this.yr=b};o_("PagingCellSet",a.zl,a);a.zl.prototype.getData=function(a){return this.sN.getData({column:a.column,row:a.row+this.yr})};a.b.g("PagingCellSet.prototype.getData",{getData:a.zl.prototype.getData});a.zl.prototype.getMetadata=function(a){return this.sN.getMetadata({column:a.column,row:a.row+this.yr})};a.b.g("PagingCellSet.prototype.getMetadata",{getMetadata:a.zl.prototype.getMetadata});a.zl.prototype.getCount=function(a){return this.sN.getCount(a)};a.b.g("PagingCellSet.prototype.getCount",
{getCount:a.zl.prototype.getCount});a.zl.prototype.ega=function(){return this.sN};a.b.g("PagingCellSet.prototype.getCellSet",{ega:a.zl.prototype.ega});a.zl.prototype.zF=function(){return this.yr};a.b.g("PagingCellSet.prototype.getStartIndex",{zF:a.zl.prototype.zF})});